<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>预录入组件登录</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'
          name='viewport'/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="cache-control" ontent="no-cache"/>
    <meta http-equiv="expires" content="0"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%
        String basePath = request.getContextPath();
    %>
    <link rel="shortcut icon" href="<%=basePath%>/images/favicon.ico" type="image/x-icon"/>

    <!--[if lt IE 9]>
    <script src="<%=basePath%>/js/html5shiv.js" type='text/javascript'></script>
    <![endif]-->
    <link href="<%=basePath%>/plugins/bootstrap-3.3.5/css/bootstrap.min.css" media='all' rel='stylesheet'
          type='text/css'/>

    <!-- / flatty theme -->
    <script src="<%=basePath%>/js/jquery/jquery-1.11.3.js" type='text/javascript'></script>
    <script type="text/javascript" src="<%=basePath%>/plugins/layer/layer.js"></script>
    <script src="<%=basePath%>/js/messagebox.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.onload = function () {
            $(document).keydown(function (e) {
                if (!e)
                    e = window.event;
                if ((e.keyCode || e.which) == 13) {
                    $("#loginButton").click();
                }
            });
        };
        //表单验证方法
        function checkForms() {
            LoginSys();
        }

        //验证密码，返回登录结果
        function LoginSys() {
            $("#loginButton").html("正在登录中...");
            var loadingIndex = layer.load(0, {offset: '60px'});
            setTimeout(function () {
                try {
                    var r = document.getElementById("AutoUpdater").Login();
                    document.getElementById("loginResult").value = r;
                    if (typeof(r) != "undefined" && r.indexOf('"Result": true') >= 0) {
                        $.post('<%=basePath%>/user/rememberICLoginInfo', {loginResult: encodeURI(r)}, function (data) {
                            if ("ok" === data) {
                                login();
                            } else {
                                $("#loginButton").html("IC卡登录");
                                layer.close(loadingIndex);
                            }
                        });
                    } else {
                        if (typeof(r) != "undefined") {
                            $("#loginButton").html("IC卡登录");
                            layer.close(loadingIndex);
                            var jsonRtn = JSON.parse(r);
                            alert(jsonRtn.Error[0]);
                        } else {
                            layer.close(loadingIndex);
                            $("#loginButton").html("IC卡登录");
                            showWarningMsg("控件登录异常，请关闭该窗口重新登录控件.");
                        }
                    }
                } catch (e) {
                    layer.close(loadingIndex);
                    $("#loginButton").html("IC卡登录");
                    showWarningMsg("控件登录异常，请关闭该窗口重新登录控件."+e);
                }
            }, 500);
        }

        function login() {
            layer.msg("使用IC卡登录成功", {
                icon: 1, time: 2000, offset: ['60px', '12%']
            }, function () {
                parent.layer.closeAll();
            });
        }
    </script>
</head>
<body>
<input type="hidden" id="loginResult"/>

<div class="row-fluid">
    <form>
        <div class="form-group">
            <label for="AutoUpdater">请输入IC卡密码:</label>
            <object id="AutoUpdater" classid="clsid:E58B9A24-1F2D-4EE7-B18C-D2F151DF77F2"
                    style="font-size: 11px;width: 250px;">
            </object>
        </div>
        <p>
        </p>
        <button type="button" class="btn btn-block btn-primary" id="loginButton"
                onclick="javascript:checkForms()">
            IC卡登录
        </button>
    </form>
</div>

</body>
</html>

